package com.qf.service;

import com.qf.dao.UserMapper;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 千锋健哥
 */
@Service("userService1")
public class UserServiceImpl implements UserService{

    //全局成员变量
    @Autowired
    private UserMapper userMapper;

//    public UserMapper getUserMapper() {
//        return userMapper;
//    }
//
//    //set方式注入使用
//    public void setUserMapper(UserMapper userMapper) {
//        this.userMapper = userMapper;
//    }

    @Override
    public List<User> findAll() {
        List<User> list = userMapper.findUserAll();
        return list;
    }

    @Override
    public User findById(Integer id) {
        User user = userMapper.findUserById(id);
        return user;
    }

    @Override
    //标记此方法使用事务的注解
    @Transactional
    public void insertUser(User user) {
        userMapper.insert(user);
        //造异常, 测试事务是否好用
        int i = 1/0;
    }

}
